using System.Collections.Generic;
using Microsoft.Web.Management.Client;
using Microsoft.Web.Management.Client.Win32;

namespace LeastPrivilege.CustomBasicAuthentication.Management
{
    class CustomBasicAuthenticationTaskList : TaskList
    {
        CustomBasicAuthenticationFeature _owner;

        public CustomBasicAuthenticationTaskList(CustomBasicAuthenticationFeature owner)
        {
            _owner = owner;
        }

        public override System.Collections.ICollection GetTaskItems()
        {
            MethodTaskItem toggleItem;
            List<TaskItem> items = new List<TaskItem>();

            if (this._owner.IsEnabled)
            {
                toggleItem = new MethodTaskItem("ToggleEnabled", "Disable", "Tasks");
            }
            else
            {
                toggleItem = new MethodTaskItem("ToggleEnabled", "Enable", "Tasks");
            }
            
            toggleItem.Enabled = !this._owner.IsLocked;
            
            items.Add(toggleItem);
            items.Add(new MethodTaskItem("EditFeatureSettings", "Edit...", "Tasks"));
            
            if (this._owner.IsLocked)
            {
                items.Add(new MessageTaskItem(MessageTaskItemType.Information, "Feature is locked", "Info"));
            }
            return items;
        }

        // task item methods
        public void EditFeatureSettings()
        {
            this._owner.EditSettings();
        }

        public void ToggleEnabled()
        {
            this._owner.ToggleEnabled();
            
        }
    }
}
